package net.chathu.airgw.packets.gw.clientpackets 
{
	import flash.utils.Dictionary;
	import net.chathu.airgw.model.Room;
	import net.chathu.airgw.packets.gw.serverpackets.EndOfListPacket;
	import net.chathu.airgw.packets.gw.serverpackets.ListItemPacket;
	import net.chathu.airgw.packets.gw.serverpackets.ListPacket;
	import net.chathu.airgw.packets.gw.serverpackets.LUsersPacket;
	/**
	 * ...
	 * @author ze
	 */
	public class CMDList extends IRCReceivablePacket 
	{
		
		public function CMDList() 
		{
			
		}
		
		override public function execute():void {
			//a LIST parancs nem kuldi el az utana irt parametereket..
			/*var filterStr:String = null;
			if (data.length > 1)
			{
				filterStr = data[1];
			}*/
			sendToClient(new ListPacket(sessionData.nick));
			
			var rooms:Dictionary = sessionData.chatData.rooms.getRoomList();
			for each(var room:Room in rooms)
			{
				//if (!filterStr && (room.name.indexOf(filterStr) >= 0 || room.topic.indexOf(filterStr) >= 0)) {
					sendToClient(new ListItemPacket(sessionData.nick, room.name, room.userNum, room.topic));
				//}
			}
			
			sendToClient(new EndOfListPacket(sessionData.nick));
			sendToClient(new LUsersPacket(sessionData.nick, sessionData.chatData.users.getUserNum()));
		}
		
		public static function getShortUsageDescription():String {
			return "Szobák listája";
		}
		
		public static function getUsageDescription():String {
			return "Példa:\n" +
				"/list\n\n" +
				"Eredmény:\n" + 
				"Sikeresen listáztad az elérhető szobákat.";
		}
	}

}